
#include "../inc/Ui/ChangeMapTypeForm.h"
#include "../inc/Ui/WebForm.h"

using namespace Osp::Base;
using namespace Osp::Ui;
using namespace Osp::Ui::Controls;

int ChangeMapTypeForm::FormId = -1;

ChangeMapTypeForm::ChangeMapTypeForm(void)
{
}

ChangeMapTypeForm::~ChangeMapTypeForm(void)
{
}

bool
ChangeMapTypeForm::Initialize()
{
	Form::Construct(L"ChangeMapTypeForm");
	return true;
}

result
ChangeMapTypeForm::OnInitializing(void)
{
	result r = E_SUCCESS;

	// TODO: Add your initialization code here
	__pChkButtonRoadmap = static_cast<CheckButton*>(GetControl(L"RdButtonRoadmap"));
	if (__pChkButtonRoadmap != null)
	{
		__pChkButtonRoadmap->SetActionId(ID_CHKBUTTON_ROADMAP, ID_CHKBUTTON_ROADMAP);
		__pChkButtonRoadmap->AddActionEventListener(*this);
	}

	__pChkButtonSatellite = static_cast<CheckButton*>(GetControl(L"RdButtonSatellite"));
	if (__pChkButtonSatellite != null)
	{
		__pChkButtonSatellite->SetActionId(ID_CHKBUTTON_SATELLITE, ID_CHKBUTTON_SATELLITE);
		__pChkButtonSatellite->AddActionEventListener(*this);
	}

	__pChkButtonHybrid = static_cast<CheckButton*>(GetControl(L"RdButtonHybrid"));
	if (__pChkButtonHybrid != null)
	{
		__pChkButtonHybrid->SetActionId(ID_CHKBUTTON_HYBRID, ID_CHKBUTTON_HYBRID);
		__pChkButtonHybrid->AddActionEventListener(*this);
	}

	__pChkButtonTerrain = static_cast<CheckButton*>(GetControl(L"RdButtonTerrain"));
	if (__pChkButtonTerrain != null)
	{
		__pChkButtonTerrain->SetActionId(ID_CHKBUTTON_TERRAIN, ID_CHKBUTTON_TERRAIN);
		__pChkButtonTerrain->AddActionEventListener(*this);
	}

	this->SetSoftkeyActionId(SOFTKEY_0, ID_SOFTKEY_OK);
	this->AddSoftkeyActionListener(SOFTKEY_0, *this);

	this->SetSoftkeyActionId(SOFTKEY_1, ID_SOFTKEY_CANCEL);
	this->AddSoftkeyActionListener(SOFTKEY_1, *this);
	return r;
}


void ChangeMapTypeForm::SetFormParent(Osp::Ui::Controls::Form *pParent)
{
	if (pParent != null)
	{
		this->__pParent = pParent;
	}
}

void ChangeMapTypeForm::SetFrame(Frame *pFrame)
{
	if (pFrame != null)
	{
		__pFrame = pFrame;
	}
}

void ChangeMapTypeForm::SetCurrentMapType(Osp::Base::String strCurrentMapType)
{
	if (strCurrentMapType.CompareTo(L"roadmap") == 0)
	{
		__pChkButtonRoadmap->SetSelected(true);
		intMapTypeId = MAPTYPE_ROADMAP;
		return;
	}

	if (strCurrentMapType.CompareTo("satellite") == 0)
	{
		__pChkButtonSatellite->SetSelected(true);
		intMapTypeId = MAPTYPE_SATELLITE;
		return;
	}

	if (strCurrentMapType.CompareTo("terrain") == 0)
	{
		__pChkButtonTerrain->SetSelected(true);
		intMapTypeId = MAPTYPE_TERRAIN;
		return;
	}

	if (strCurrentMapType.CompareTo("hybrid") == 0)
	{
		__pChkButtonHybrid->SetSelected(true);
		intMapTypeId = MAPTYPE_HYBRID;
	}
}

void ChangeMapTypeForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
{
	FormManager *pFormManager;
	FormManager::GetInstance(pFormManager);
	//MyFormAbstract *pWebForm = null;
	switch (actionId)
	{
	case ID_SOFTKEY_OK:
		AppLog("Softkey Ok");

		pFormManager->SetCurrentForm(WebForm::GetFormId());

		WebController::SetMapTypeIdN(intMapTypeId);
		break;

	case ID_SOFTKEY_CANCEL:
		AppLog("Softkey Cancel");
		pFormManager->SetCurrentForm(WebForm::GetFormId());
		break;

	case ID_CHKBUTTON_ROADMAP:
		AppLog("CheckButton Roadmap");

		intMapTypeId = MAPTYPE_ROADMAP;
		break;

	case ID_CHKBUTTON_SATELLITE:
		AppLog("CheckButton Satellite");

		intMapTypeId = MAPTYPE_SATELLITE;
		break;

	case ID_CHKBUTTON_HYBRID:
		AppLog("CheckButton Hybrid");

		intMapTypeId = MAPTYPE_HYBRID;
		break;

	case ID_CHKBUTTON_TERRAIN:
		AppLog("CheckButton Terrain");

		intMapTypeId = MAPTYPE_TERRAIN;
		break;

	default:
		break;
	}
}

result
ChangeMapTypeForm::OnTerminating(void)
{
	result r = E_SUCCESS;

	// TODO: Add your termination code here

	return r;
}


